<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>菜单管理-${sysName}</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="${resRoot}/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="${resRoot}/layui/admin/admin.css" media="all" />
	<link id="layuicss-layer" rel="stylesheet" href="${resRoot}/layui/css/modules/layer/default/layer.css?v=2018-07-31" media="all">
</head>
<body class="childrenBody">
<div class="layui-fluid">   
          <div class="layui-card">
<@shiro.hasPermission name="menu:save">
<div class="layui-form layui-card-header layuiadmin-card-header-auto">
	<div class="layui-form-item">
<div class="site-demo-button" style="margin-bottom: 0;">
  <a class="layui-btn linksAdd_btn" style="background-color:#5FB878" onclick="editData()" href="javascript:void(0);">新增菜单</a>
  </div>
  </div>
  </div>
  </@shiro.hasPermission>
 
  
  <div class="layui-card-body">
<div class="layui-form">

		<table class="layui-table">
    <colgroup>
      <col width="250">
      <col width="250">
      <col width="200">
      <col>
    </colgroup>
    <thead>
      <tr>
        <th>菜单名称</th>
        <th>菜单URL</th>
        <th>授权</th>
        <th>操作</th>
      </tr> 
    </thead>
    <tbody class="tbDatalist" id="tbDatalist">
    
    </tbody>
  </table>
  
</div>
</div>
 </div>
  </div>
	<script type="text/javascript" src="${resRoot}/layui/layui.js"></script>
	<script src="${resRoot}/js/jquery.min.js?v=2.1.4"></script>
	<script src="${resRoot}/layui/layui.all.js" charset="utf-8"></script>
<script>

$(document).ready(function(){
	layer.msg('加载中...',{
		icon:16,
		shade:0.5
	});
	$.ajax({
		type : "post",
		url : "${base}/sys/menu/jsShow",
		data : {},
		dataType : "json",
		async : true,
		success : function(data) {
			if(data.message != '' && data.message != null ) {
				 var obj = data.message;
				 var html = "";
				 var b = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
				 html = getHtml(obj,html,b);
				 $("#tbDatalist").html(html);
				} else {
				layer.msg("当前分类下含有子分类，请先删除子分类");
				}
		}
	}); 
	layer.closeAll(); 
})

function getHtml(obj, html, b) {
	 var objChild = obj;
	 for(var item in objChild) {
		 var iconTmp = objChild[item].icon;
		 if(iconTmp == ""|| iconTmp==null || iconTmp=="undefined") {
			 iconTmp = "";
		 }
		 var url1 =  objChild[item].url;
		 if(url1 == ""|| url1==null || url1=="undefined") {
			 url1 = "";
		 }
		 var perms1 = objChild[item].perms;
		 
		 if(perms1 == ""|| perms1==null || perms1=="undefined") {
			 perms1 = "";
		 }
		 if(objChild[item].type!=2 ) {
				 
			 html =html + "<tr><td>" + b + "<i class='layui-icon' data-icon='" + iconTmp + "'>" + iconTmp+ "</i> " + objChild[item].name + "</td><td>" + url1+ "</td><td>" + perms1+ "</td><td><@shiro.hasPermission name='menu:save'><a class='layui-btn layui-btn-normal layui-btn-xs' id='editData' onclick='editData(" + objChild[item].id  + ");' dataId='" + objChild[item].id  + "' href='javascript:void(0);'><i class='iconfont icon-edit'></i>修改</a></@shiro.hasPermission> <@shiro.hasPermission name='menu:del'><a class='layui-btn layui-btn-danger layui-btn-xs' href='javascript:void(0);' onclick='del(" + objChild[item].id+");' ><i class='layui-icon'></i>删除</a></@shiro.hasPermission> <@shiro.hasPermission name='menu:save'><a class='layui-btn layui-btn-normal layui-btn-xs' onclick='addByParentIdData(" + objChild[item].id + ");' href='javascript:void(0);'><i class='iconfont icon-edit'></i>添加下级菜单</a></@shiro.hasPermission></td></tr>";
		 } else {
			 html =html + "<tr><td>" + b + "<i class='layui-icon' data-icon='" + iconTmp + "'>" + iconTmp+ "</i> " + objChild[item].name + "</td><td>" + url1+ "</td><td>" + perms1+ "</td><td><@shiro.hasPermission name='menu:save'><a class='layui-btn layui-btn-normal layui-btn-xs' id='editData' onclick='editData(" + objChild[item].id  + ");' dataId='" + objChild[item].id  + "' href='javascript:void(0);'><i class='iconfont icon-edit'></i>修改</a></@shiro.hasPermission> <@shiro.hasPermission name='menu:del'><a class='layui-btn layui-btn-danger layui-btn-xs' href='javascript:void(0);' onclick='del(" + objChild[item].id+");' ><i class='layui-icon'></i>删除</a></@shiro.hasPermission> <@shiro.hasPermission name='menu:save'></@shiro.hasPermission></td></tr>";
		 }
		 if(objChild[item].childMenu !="undefined" &&  objChild[item].childMenu != null && objChild[item].childMenu !='' && objChild[item].childMenu.length>0) {
			 var b1 = b + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
			 var objChildC = objChild[item].childMenu;
			 
			 for(var items in objChildC) {
			 var iconTmp1 = objChildC[items].icon;
			 if(iconTmp1 == ""|| iconTmp1==null || iconTmp1=="undefined") {
				 iconTmp1 = "";
			 }
			 var url2 =  objChildC[items].url;
			 if(url2 == ""|| url2==null || url2=="undefined") {
				 url2 = "";
			 }
			 var perms2 = objChildC[items].perms;
			 
			 if(perms2 == ""|| perms2==null || perms2=="undefined") {
				 perms2 = "";
			 }
				 if(objChildC[items].type!=2 ) {
					 html =html + "<tr><td>" + b1 + "<i class='layui-icon' data-icon='" + iconTmp1 + "'>" + iconTmp1+ "</i> " + objChildC[items].name + "</td><td>" + url2+ "</td><td>" + perms2+ "</td><td><@shiro.hasPermission name='menu:save'><a class='layui-btn layui-btn-normal layui-btn-xs' id='editData' onclick='editData(" + objChildC[items].id  + ");' dataId='" + objChildC[items].id  + "' href='javascript:void(0);'><i class='iconfont icon-edit'></i>修改</a></@shiro.hasPermission> <@shiro.hasPermission name='menu:del'><a class='layui-btn layui-btn-danger layui-btn-xs' href='javascript:void(0);' onclick='del(" + objChildC[items].id+");' ><i class='layui-icon'></i>删除</a></@shiro.hasPermission> <@shiro.hasPermission name='menu:save'><a class='layui-btn layui-btn-normal layui-btn-xs' onclick='addByParentIdData(" + objChildC[items].id + ");' href='javascript:void(0);' ><i class='iconfont icon-edit'></i>添加下级菜单</a></@shiro.hasPermission></td></tr>";
				 } else {
					 html =html + "<tr><td>" + b1 + "<i class='layui-icon' data-icon='" + iconTmp1 + "'>" + iconTmp1+ "</i> " + objChildC[items].name + "</td><td>" + url2+ "</td><td>" + perms2+ "</td><td><@shiro.hasPermission name='menu:save'><a class='layui-btn layui-btn-normal layui-btn-xs' id='editData' onclick='editData(" + objChildC[items].id  + ");' dataId='" + objChildC[items].id  + "' href='javascript:void(0);'><i class='iconfont icon-edit'></i>修改</a></@shiro.hasPermission> <@shiro.hasPermission name='menu:del'><a class='layui-btn layui-btn-danger layui-btn-xs' href='javascript:void(0);' onclick='del(" + objChildC[items].id+");' ><i class='layui-icon'></i>删除</a></@shiro.hasPermission> <@shiro.hasPermission name='menu:save'></@shiro.hasPermission></td></tr>";
				 }
				 if(objChildC[items].childMenu !="undefined" &&  objChildC[items].childMenu != null && objChildC[items].childMenu !='' && objChildC[items].childMenu.length>0) {
					 var b2 = b1 + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
					 var objChildCC = objChildC[items].childMenu;
					 for(var itemss in objChildCC) {
						 var iconTmp2 = objChildCC[itemss].icon;
						 if(iconTmp2 == ""|| iconTmp2==null || iconTmp2=="undefined") {
							 iconTmp2 = "";
						 }
						 
						 var url3 =  objChildCC[itemss].url;
						 if(url3 == ""|| url3==null || url3=="undefined") {
							 url3 = "";
						 }
						 var perms3 = objChildCC[itemss].perms;
						 
						 if(perms3 == ""|| perms3==null || perms3=="undefined") {
							 perms3 = "";
						 }
						 if(objChildCC[itemss].type!=2 ) {
							 html =html + "<tr><td>" + b2 + "<i class='layui-icon' data-icon='" + iconTmp2 + "'>" + iconTmp2+ "</i> " + objChildCC[itemss].name + "</td><td>" + url3+ "</td><td>" + perms3+ "</td><td><@shiro.hasPermission name='menu:save'><a class='layui-btn layui-btn-normal layui-btn-xs' id='editData' onclick='editData(" + objChildCC[itemss].id  + ");' dataId='" + objChildCC[itemss].id  + "' href='javascript:void(0);'><i class='iconfont icon-edit'></i>修改</a></@shiro.hasPermission> <@shiro.hasPermission name='menu:del'><a class='layui-btn layui-btn-danger layui-btn-xs' href='javascript:void(0);' onclick='del(" + objChildCC[itemss].id+");' ><i class='layui-icon'></i>删除</a></@shiro.hasPermission> <@shiro.hasPermission name='menu:save'><a class='layui-btn layui-btn-normal layui-btn-xs' onclick='addByParentIdData(" + objChildCC[itemss].id + ");' href='javascript:void(0);' ><i class='iconfont icon-edit'></i>添加下级菜单</a></@shiro.hasPermission></td></tr>";
						 } else {
							 html =html + "<tr><td>" + b2 + "<i class='layui-icon' data-icon='" + iconTmp2 + "'>" + iconTmp2+ "</i> " + objChildCC[itemss].name + "</td><td>" + url3+ "</td><td>" + perms3+ "</td><td><@shiro.hasPermission name='menu:save'><a class='layui-btn layui-btn-normal layui-btn-xs' id='editData' onclick='editData(" + objChildCC[itemss].id  + ");'  dataId='" + objChildCC[itemss].id  + "'  href='javascript:void(0);'><i class='iconfont icon-edit'></i>修改</a></@shiro.hasPermission> <@shiro.hasPermission name='menu:del'><a class='layui-btn layui-btn-danger layui-btn-xs' href='javascript:void(0);' onclick='del(" + objChildCC[itemss].id+");' ><i class='layui-icon'></i>删除</a></@shiro.hasPermission> <@shiro.hasPermission name='menu:save'></@shiro.hasPermission></td></tr>";
						 }
					 }
				 }
			 }
			 
		 }
	 }

	 return html;
}



function del(id) {
	layer.confirm('确定删除该条菜单吗?', function(index){
	$.ajax({
		type : "post",
		url : "${base}/sys/menu/del",
		data : {
			id : id
			},
		dataType : "json",
		async : false,
		success : function(data) {
			if(data.message == 0) {
				layer.msg('删除成功！', {
					  icon: 1,
					  time: 2000 //2秒关闭（如果不配置，默认是3秒）
					}, function(){
					  //do something
						window.location.href="${base}/sys/menu/show";
					});   
				} else {
				layer.msg("当前分类下含有子分类，请先删除子分类");
				}
		}
	}); 
	});   
}

function editData(id){
	// var id = $(this).attr("dataId");
  	addData(id, null);
}
 
 function addByParentIdData(parendtId){
		// var id = $(this).attr("dataId");
	  	addData(null,parendtId);
	}
 
 function addData(id, parendtId){
		var url = "${base}/sys/menu/tosave";
		var titleStr = "添加菜单";
		if(id){
			url = "${base}/sys/menu/tosave?id=" + id;
			titleStr = "修改用户";
		}
		if(parendtId) {
			url = "${base}/sys/menu/tosave?parentId=" + parendtId ;
		}
        var index = layui.layer.open({
            title : titleStr,
            type : 2,
            content : url,
            success : function(layero, index){
                var body = layui.layer.getChildFrame('body', index);
                setTimeout(function(){
                    layui.layer.tips('点击此处返回', '.layui-layer-setwin .layui-layer-close', {
                        tips: 3
                    });
                },500)
            }
        })
        layui.layer.full(index);
        //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
        $(window).on("resize",function(){
            layui.layer.full(index);
        })
    }

</script>
</body>
</html>